package middleware

import (
	"gitee.com/yangguoliang001/go-gin-vue3/services/adminService"
	"github.com/gin-gonic/gin"
	"github.com/go-redis/redis/v7"
	"go.uber.org/zap"
	"gorm.io/gorm"
)

var _ Interceptor = (*interceptor)(nil)

type Interceptor interface {
	RGBAMiddleware() gin.HandlerFunc
}

type interceptor struct {
	logger       *zap.Logger
	cache        *redis.Client
	db           *gorm.DB
	adminService *adminService.AdminService
}

func New(logger *zap.Logger, db *gorm.DB, cache *redis.Client) Interceptor {
	return &interceptor{
		logger:       logger,
		cache:        cache,
		db:           db,
		adminService: adminService.New(db, cache),
	}
}
